<?php

namespace App\Http\Controllers\User;

use App\Common\JwtAuth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    //

    public function getToken(Request $request)
    {
        $userId = $request->post('userid');
        $token = JwtAuth::getToken(array(
            'user_id' => $userId
        ));
        return $token;
    }

    public function checkToken(Request $request)
    {
        $header = $request->header('Authorization');//验证
        $token = explode(' ',$header);
        if(!$header || !$token){
            return $this->json(419,'登录信息已过期，重新登录');
        }
        $data = JwtBase::verifyToken($token[1]);
        if(!$data){
            return $this->json(419,'登录信息已过期，重新登录');
        }
    }
}
